package com.newsee.remote.common.bean;

import com.newsee.remote.common.enumeration.ResponseCode;
import io.swagger.annotations.ApiModel;

import java.util.LinkedHashMap;

/**
 * json返回结果封装
 *
 * @author liangzhichen
 */
@ApiModel
public class JsonResult extends LinkedHashMap<String, Object> {
    private static final long serialVersionUID = 4004136263013658272L;

    private static final String CODE = "code";

    private static final String ERROR_CODE = "errorCode";

    private static final String DATA = "data";

    public JsonResult() {
        setCode(ResponseCode.OK);
    }

    public JsonResult(ResponseCode code) {
        setCode(code);
    }

    public JsonResult(ResponseCode code, String errorCode) {
        setCode(code);
        setErrorCode(errorCode);
    }

    public JsonResult(Object data) {
        setCode(ResponseCode.OK);
        setData(data);
    }

    public ResponseCode getCode() {
        return ResponseCode.genEnum((int) get(CODE));
    }

    public void setCode(ResponseCode code) {
        put(CODE, code.getCode());
    }

    public String getErrorCode() {
        return String.valueOf(get(ERROR_CODE));
    }

    public void setErrorCode(String errorCode) {
        put(ERROR_CODE, errorCode);
    }

    public Object getData() {
        return get(DATA);
    }

    public void setData(Object data) {
        put(DATA, data);
    }
}
